package models

import (
	"fmt"
	"github.com/astaxie/beego/orm"
)

type SysCat struct {
	Id                int    `orm:"column(id);auto"`
	CategoryFullname  string `orm:"column(category_fullname);size(6)" description:"长名称"`
	CategoryShortname string `orm:"column(category_shortname);size(2)" description:"短名称"`
	CategoryType      int8   `orm:"column(category_type)" description:"类型"`
	OssPath           string `orm:"column(oss_path);size(6)" description:"OSS路径"`
	ChannelType       int8   `orm:"column(channel_type)" description:"频道类型"`
	UsedName          string `orm:"column(used_name);size(6);null" description:"曾用名"`
}

func (t *SysCat) TableName() string {
	return "sys_cat"
}

func init() {
	orm.RegisterModel(new(SysCat))
}

// AddSysCat insert a new SysCat into database and returns
// last inserted Id on success. GetAllSysCat
func GetAllSysCat() ([]*SysCat,error) {
	o := orm.NewOrm()
	sysCats := make([]*SysCat,0)
	_, err := o.Raw("SELECT * from sys_cat").QueryRows(&sysCats)
	if err != nil {
		fmt.Println("select sys_cat error",err)
		return nil,err
	}
	return sysCats, nil
}
